﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoccerSimulator5000
{
    public class TeamData
    {
        public float forwardScore { get; set; }
        public float midfieldScore { get; set; }
        public float defenderScore { get; set; }
        public float goalieScore { get; set; }
        public float totalScore { get; set; }

        public Squad squad { get; set; }

        public TeamData()
        {
            
        }

        // Part of attempt to solve load-issue
        public void NewTeamData()
        {
            squad = new Squad();
            squad.Init();
            UpdateData();
        }


        public void UpdateData()
        {
            float tempScore = 0;
            // Update forwardScore
            for (int i = 0; i <= squad.attackers.Count(); i++ )
            {
                
                if (i != squad.attackers.Count())
                {
                    tempScore += squad.attackers[i].attacking;
                }
                else
                {
                    forwardScore = tempScore / (squad.attackers.Count);
                }

            }
            tempScore = 0;
            // Update midfieldScore
            for (int i = 0; i <= squad.midfielders.Count(); i++)
            {
                if (i != squad.midfielders.Count())
                {
                    tempScore += squad.midfielders[i].midfield;
                }
                else
                {
                    midfieldScore = tempScore / (squad.midfielders.Count);
                }

            }
            tempScore = 0;
            // Update defenderScore
            for (int i = 0; i <= squad.defenders.Count(); i++)
            {
                if (i != squad.defenders.Count())
                {
                    tempScore += squad.defenders[i].defending;
                }
                else
                {
                    defenderScore = tempScore / (squad.defenders.Count);
                }

            }

            // Update goalieScore

            goalieScore = squad.goalkeeper[0].goalkeeping;

            totalScore = (forwardScore + midfieldScore + defenderScore + goalieScore) / 4;
        }

        public void Draw( System.Drawing.Graphics g, int x, int y )
        {
            int fontSize = 10;
            g.DrawString(("Forwards: " + forwardScore), new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, fontSize-1), System.Drawing.Brushes.Black, new System.Drawing.PointF(x, y));
            g.DrawString(("Midfielders: " + midfieldScore), new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, fontSize-1), System.Drawing.Brushes.Black, new System.Drawing.PointF(x, y + fontSize));
            g.DrawString(("Defenders: " + defenderScore), new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, fontSize-1), System.Drawing.Brushes.Black, new System.Drawing.PointF(x, y + fontSize*2));
            g.DrawString(("Goalie: " + goalieScore), new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, fontSize - 1), System.Drawing.Brushes.Black, new System.Drawing.PointF(x, y + fontSize * 3));
            g.DrawString(("Total: " + totalScore), new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, fontSize-1), System.Drawing.Brushes.Black, new System.Drawing.PointF(x, y + fontSize*4));
        }

    }
}
